Skip to content

Enable THD with hierarchical context parallelism - #3290

Merged
sudhakarsingh27 merged 1 commit into
NVIDIA:mainfrom
sudhakarsingh27:sudhakars/enable-thd-hierarchical-cp
Aug 5, 2026
Merged

Enable THD with hierarchical context parallelism#3290
sudhakarsingh27 merged 1 commit into
NVIDIA:mainfrom
sudhakarsingh27:sudhakars/enable-thd-hierarchical-cp

Conversation

@sudhakarsingh27

Copy link
Copy Markdown
Member

Description

The THD-aware A2A and P2P paths already compose correctly and match the non-CP reference in forward and backward passes. Remove the stale runtime and backend gates, and enable the existing FlashAttention and FusedAttention test coverage for this combination.
Fixes # (issue)

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

Please list the changes introduced in this PR:

Only removes filters which are no longer necessary

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

The THD-aware A2A and P2P paths already compose correctly and match the non-CP reference in forward and backward passes. Remove the stale runtime and backend gates, and enable the existing FlashAttention and FusedAttention test coverage for this combination.

Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
@sudhakarsingh27 sudhakarsingh27 self-assigned this Jul 30, 2026
@sudhakarsingh27
sudhakarsingh27 marked this pull request as ready for review August 4, 2026 23:14
@sudhakarsingh27

Copy link
Copy Markdown
Member Author

/te-ci pytorch L1

@greptile-apps

greptile-apps Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR enables packed THD tensors with hierarchical context parallelism by removing stale runtime, backend-selection, and test-suite exclusions.

  • Allows thd inputs through the hierarchical A2A+P2P context-parallel dispatcher.
  • Permits FusedAttention backend selection for THD with hierarchical context parallelism while retaining existing mask, bias, FP8, sliding-window, topology, and head-count guards.
  • Extends FlashAttention and FusedAttention distributed numerical test matrices to cover the newly enabled combination.

Confidence Score: 5/5

The PR appears safe to merge because the newly enabled hierarchical THD path composes existing THD-aware A2A and P2P implementations and remains protected by the relevant backend compatibility checks.

The removed gates expose an implementation with dedicated THD sequence reordering, padded-sequence metadata handling, output correction, and backward gradient correction, and the distributed tests compare its forward and backward results against the non-context-parallel reference.

Important Files Changed

Filename Overview
transformer_engine/pytorch/attention/dot_product_attention/context_parallel.py Removes the THD rejection from hierarchical A2A+P2P dispatch; existing THD-specific sequence reordering and forward/backward correction paths handle the enabled flow.
transformer_engine/pytorch/attention/dot_product_attention/utils.py Removes the stale FusedAttention eligibility filter while preserving other compatibility guards for hierarchical THD attention.
tests/pytorch/attention/test_attention_with_cp.py Enables hierarchical THD cases in both distributed FlashAttention and FusedAttention numerical test matrices.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["THD Q/K/V and sequence metadata"] --> B["Backend selection"]
  B --> C["Hierarchical CP dispatcher"]
  C --> D["A2A head exchange"]
  D --> E["P2P context ring"]
  E --> F["FlashAttention or FusedAttention"]
  F --> G["A2A output exchange"]
  G --> H["THD output"]
Loading

Reviews (1): Last reviewed commit: "Enable THD with hierarchical context par..." | Re-trigger Greptile

@sudhakarsingh27
sudhakarsingh27 merged commit 8ff60f8 into NVIDIA:main Aug 5, 2026
11 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants